package cn.rengy.web.framework.web;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.permission.AllPermission;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import cn.rengy.lang.ResultEntity;
import lombok.Getter;
import lombok.Setter;


/**
 * test
 * 
 */
@RestController
@RequestMapping
public class TestController {
	@Autowired
	private StringRedisTemplate stringRedisTemplate;
	@Autowired
	private RedisTemplate<Object,Object> redisTemplate;
	@Autowired
	private JdbcTemplate jdbcTemplate;
	@Getter
	@Setter
	class User{
		private Long age=new Long(99);
		private long size=88;
	}
	@RequestMapping(value="/test/test4",method = RequestMethod.POST)
	public ResultEntity<?> test4 (){
		Map m=jdbcTemplate.queryForMap("select * from test where age=?", "2");
		return ResultEntity.ok(m);
	}
	@RequestMapping(value="/authenticated/test/test3",method = RequestMethod.POST)
	public ResultEntity<?> test3 (){
		Subject subject = SecurityUtils.getSubject();
		subject.checkPermission(new AllPermission());
		return ResultEntity.ok();
	}
	@RequestMapping(value="/test2",method = RequestMethod.POST)
	public ResultEntity<?> test2 (){
		User u=new User();
		String key="a";
		stringRedisTemplate.opsForValue().set(key, "1");
		redisTemplate.opsForValue().set("b", 1);
		
		redisTemplate.opsForList().leftPush("list1", u);
		return ResultEntity.ok();
	}
	/**
	 * 测试jackson
	 * @return
	 */
	@RequestMapping(value="/test",method = RequestMethod.POST)
	public ResultEntity<?> test (){
		Map<String,Object> data=new HashMap<String,Object>();
		data.put("long", 999L);
		data.put("Long", new Long(11));
		data.put("int", 3);
		data.put("bigdecimal", new BigDecimal(Long.MAX_VALUE));
		User u=new User();
		data.put("user", u);
		return ResultEntity.ok(data);
	}
	public static void main(String[] args) {
		long l=3;
		Object o=l;
		System.out.println(long.class);
		System.out.println(Long.class);
		System.out.println(o  instanceof Long);
	}
}
